<template>
	<view class="fill_wp">
		<div class="h"></div>
		<view class="fill_con bg_bai" style="margin-top: 0;">			
			<view class="item">
				<view class="span">手机号</view>
				<input class="uni_input" type="text" v-model="phone" disabled placeholder="请输入" />
			</view>
			<!-- <view class="item">
				<view class="span">原密码</view>
				<input class="uni_input" type="text" placeholder="请输入" />
			</view> -->
			<view class="item">
				<view class="span">新密码</view>
				<input class="uni_input" type="idcard" v-model="new_password" placeholder="请输入" />
			</view>
			<view class="item">
				<view class="span">确认新密码</view>
				<input class="uni_input" type="idcard" v-model="new_password_confirmation" placeholder="请输入" />
			</view>
		</view>
		<view class="h"></view>
		<view class="food_btn">
			<view class="food_btn_con">
				<text class="btn btn_two" @click="SubMit()">确定</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone:'',
				new_password:'',
				new_password_confirmation:''
			}
		},
		onLoad() {
			let that = this;
			if (that.common.GetStorage('byh5token')) {
				that.logintype = that.common.GetStorage('byh5type');				
				that.GetUserMass();
				
			} else {
				uni.reLaunch({
					url: '/pages/login/login',
				})
			}
		},
		methods: {			
			GetUserMass:function(){
				let that = this;
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				that.common.http('GET', 'user', '', function(res) {
					uni.hideLoading();
					that.phone = res.data.phone;
				});
			},
			
			SubMit:function(){
				let that = this;
				if (that.new_password == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入新密码',
						duration: 2000
					});
				}
				else if (that.new_password_confirmation == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入确认新密码',
						duration: 2000
					});
				}
				else if (that.new_password_confirmation != that.new_password) {
					uni.showToast({
						icon: 'none',
						title: '两次密码不一致',
						duration: 2000
					});
					that.new_password_confirmation = '';
				}
				else{
					let _data = {
						phone:that.phone,
						new_password:that.new_password,
						new_password_confirmation:that.new_password_confirmation,
					}
					uni.showLoading({
						title: '加载中...',
						mask: true
					});
					that.common.http('PUT', 'user/repassword', _data, function(res) {
						uni.showToast({
							icon: 'none',
							title: '修改成功！',
							duration: 2000
						});
						setTimeout(function() {
							that.navigateBack();
						}, 1500);
					});
				}
			},
			
			navigateBack() {
				// #ifdef H5
				const pages = getCurrentPages()
				if (pages.length > 1) {
					uni.navigateBack(1)
					return;
				}
				//使用vue-router返回上一级
				let a = this.$router.go(-1)
				if (a == undefined) {}
				return;
				// #endif
				uni.navigateBack();
			},
			
		}
	}
</script>

<style scoped>	
	.mt30 {
		margin-top: 30rpx;
	}
</style>